#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;

const int N = 3e5 + 10;

int n, m;
int l[N], r[N], e[N], idx;
int mp[N];
bool st[N];

void init(){
    r[0] = 1;
    l[1] = 0;
    
    idx = 2;
}

void addl(int cur, int x){
    mp[x] = idx;
    e[idx] = x;
    int prev = l[cur];
 //   cout << prev << " " << r[prev] << '\n';
    r[prev] = idx;
    l[idx] = prev;
    r[idx] = cur;
    l[cur] = idx;
    
    idx ++;
}

void addr(int cur, int x){
    addl(r[cur], x);
}

void dele(int x){
    int p = mp[x];
    int prev = l[p], ne = r[p];
    r[prev] = ne;
    l[ne] = prev;
}


int main(){
#ifdef LOCALFLAG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif


    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    init();
    cin >> n;
    addr(0, 1);
    // cout << r[0];

    // exit(0);
    for(int i = 2; i <= n; i ++){
        int x, p;
        cin >> x >> p;
        if(p == 0){
            addl(mp[x], i);
        }else{
            addr(mp[x], i);
        }
    }

    cin >> m;
    for(int i = 1; i <= m; i ++){
        int x;
        cin >> x;
        if(st[x]) continue;
        dele(x);
        st[x] = true;
    }


    int p = r[0];
    while(p != 1){
        cout << e[p] << " ";
        p = r[p];
    }




    return 0;
}